<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <meta name="keywords">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/templates/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
    <link href="/templates/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="/templates/vendor/animate/animate.css" rel="stylesheet">
    <link href="/templates/vendor/hplus/hplus.css?v=4.1.0" rel="stylesheet">
    <link href="/templates/vendor/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/templates/vendor/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="/templates/vendor/iCheck/custom.css" rel="stylesheet">
    <link href="/templates/vendor/chosen/chosen.css" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="/templates/vendor/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="/templates/vendor/datapicker/datepicker3.css">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户管理</h5>
                </div>
                <div class="ibox-content">
                    <div class="row row-lg">
                        <div class="col-sm-12">
                            <div class="btn-group hidden-xs" id="hotel_goods_toolbar" role="group">
                                <a type="button" class="btn btn-w-m btn-block btn-primary" href="{:url('Admin/editAdmin',array('id'=>0))}" data-toggle="modal" data-target="#myModal2">新增</a>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-12">
                            <style type="text/css">
                                .fixed-table-pagination{
                                    margin-bottom: 20px;
                                    margin-left: 10px;
                                    margin-right: 10px;
                                }
                            </style>
                            <table id="admin_list" class="table table-striped" data-mobile-responsive="true">
                                <thead>
                                <tr>
                                    <th data-field="admin_id">ID</th>
                                    <th data-field="admin_name">用户名</th>
                                    <th data-field="role_name" data-sortable="true">角色</th>
                                    <th data-field="is_super" data-sortable="true">系统超级管理员</th>
                                    <th data-field="admin_login_time" data-sortable="true">最后登录时间</th>
                                    <th data-field="admin_login_num" data-sortable="true">登录次数</th>
                                    <th data-field="is_member" data-sortable="true">是否绑定前台会员</th>
                                    <th data-field="member_name" data-sortable="true">前台会员帐号</th>
                                    <th data-sortable="true" data-formatter="buttonFormatter" data-events="operateEvents" >操作</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated ">

            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="/templates/vendor/jquery/jquery.min.js?v=2.1.4"></script>
<script src="/templates/vendor/bootstrap/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="/templates/vendor/content/content.js?v=1.0.0"></script>
<!-- Bootstrap table -->
<script src="/templates/vendor/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/templates/vendor/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="/templates/vendor/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<script src="/templates/vendor/layer/layer.min.js"></script>
<script src="/templates/vendor/jasny/jasny-bootstrap.min.js"></script>
<script src="/templates/vendor/iCheck/icheck.min.js"></script>

<!-- Clock picker -->
<script src="/templates/vendor/chosen/chosen.jquery.js"></script>
<script src="/templates/vendor/suggest/bootstrap-suggest.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

        <!-- 移除旧数据 -->
        $("#myModal2").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });

        function getTab(){
            $("#admin_list").bootstrapTable({
                method: "post", //这里要设置为get，不知道为什么 设置post获取不了
                url: "{:url('Admin/index')}",
                cache: false,
                height: "100%",
                striped: true,
                sortable: false,      //是否启用排序
                sortOrder: "asc",     //排序方式
//                pagination: true,
                // contentType: "application/x-www-form-urlencoded",
                pageSize:10,
                pageNumber:1,
                search: true,
                sidePagination: "server",//设置为服务器端分页
                queryParams: queryParams,//参数
                queryParamsType: "limit",
                showColumns: true,
                showRefresh: true,
                minimumCountColumns: 2,
                clickToSelect: true,
                smartDisplay:true,
                icons: {
                    refresh: 'glyphicon-repeat',
                    toggle: 'glyphicon-list-alt',
                    columns: 'glyphicon-list'
                }
            });
        }

        //设置传入参数
        function queryParams(params) {
            params.action   =   "show";
            return params
        }

        $(function(){
            getTab();
        });
    });

    function buttonFormatter(value, row) {
        var url     =   "<?php echo url('Admin/editAdmin');?>?id="+row.admin_id;
        if(row.admin_is_super == 1){
            return [
                '<a type="button" href="'+ url +'" class="btn btn-primary btn_edit" data-toggle="modal" data-target="#myModal2" >编辑</a> '

            ].join('');
        }
        return [
            '<a type="button" href="'+ url +'" class="btn btn-primary btn_edit" data-toggle="modal" data-target="#myModal2" >编辑</a> ',
            '<a data-toggle="modal" class="btn btn-danger btn_delete">删除</a> ',

        ].join('');

    }

    window.operateEvents = {
        'click .btn_delete':function(e,value,row,index){
            layer.confirm('是否确定删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(index, layero){
                var params = {
                    id:row.admin_id
                }
                $.post("{:url('Admin/delete')}",params,function(result){
                    parent.layer.msg(result.msg);
                    setTimeout(function(){
                        $('#admin_list').bootstrapTable('refresh', null);
                        layer.closeAll();
                    },3000);
                },'json');
            }, function(index){
                console.log('取消删除');
            });
        }
    }

</script>
<style>
    .chosen-container-single .chosen-single {
        background: #ffffff;
        box-shadow: none;
        -moz-box-sizing: border-box;
        background-color: #FFFFFF;
        border: 1px solid #CBD5DD;
        border-radius: 2px;
        cursor: text;
        height: auto !important;
        margin: 0;
        min-height: 30px;
        overflow: hidden;
        padding: 4px 12px;
        position: relative;
        width: 100%;
    }
</style>

</body>

</html>

